﻿using MaterialDesignThemes.Wpf;
using RotovapPlatform.UI.Services;
using RotovapPlatform.UI.Views.Dialogs;

public class MessageService : IMessageService
{
	public async Task ShowInfoAsync(string message, string title = "提示")
	{
		var view = new MessageDialog
		{
			Message = { Text = message },
			Title = { Text = title },
			Icon = { Kind = PackIconKind.Information }
		};
		await DialogHost.Show(view, "RootDialog");
	}

	public async Task ShowWarningAsync(string message, string title = "警告")
	{
		var view = new MessageDialog
		{
			Message = { Text = message },
			Title = { Text = title },
			Icon = { Kind = PackIconKind.Alert }
		};
		await DialogHost.Show(view, "RootDialog");
	}

	public async Task ShowErrorAsync(string message, string title = "错误")
	{
		var view = new MessageDialog
		{
			Message = { Text = message },
			Title = { Text = title },
			Icon = { Kind = PackIconKind.Error }
		};
		await DialogHost.Show(view, "RootDialog");
	}

	public async Task ShowSuccessAsync(string message, string title = "成功")
	{
		var view = new MessageDialog
		{
			Message = { Text = message },
			Title = { Text = title },
			Icon = { Kind = PackIconKind.CheckCircle }
		};
		await DialogHost.Show(view, "RootDialog");
	}

	public async Task<bool> ShowConfirmAsync(string message, string title = "确认")
	{
		try
		{
			var view = new ConfirmDialog
			{
				Message = { Text = message },
				Title = { Text = title }
			};

			var result = await DialogHost.Show(view, "RootDialog");
			return result?.ToString()?.ToLower() == "true";
		}
		catch (Exception)
		{
			return false;
		}
	}
}